package com.daxilong.starchen.player.utils;

import com.daxilong.starchen.player.api.ApiService;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class HttpUtils {

    private static final String BASE_URL = "http://192.168.43.21:10030/";

    public static ApiService getApiService() {
        // 1. 创建 OkHttpClient（可自定义超时、拦截器等）
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)) // 日志拦截器
                .build();

        // 2. 创建 Retrofit 实例
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .client(okHttpClient) // 绑定 OkHttp
                .addConverterFactory(GsonConverterFactory.create()) // 使用 Gson 解析 JSON
                .build();

        // 3. 返回 ApiService 实例
        return retrofit.create(ApiService.class);
    }

}
